package com.ly.controller;

import com.ly.entities.CommonResult;
import com.ly.entities.Payment;
import com.ly.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.utils.DateUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

@RequestMapping("consumer")
@RestController
@Slf4j
public class OrderFeignController {

    @Resource
    private PaymentFeignService paymentFeignService;

    @GetMapping("/payment/getFeign/{id}")//可以自定义的方法路径
    public CommonResult<Payment> getPayment(@PathVariable("id") String id) {
        return paymentFeignService.getPaymentById2222(id);
    }

    /**
     * 演示openFign超时设置，故意设置超时演示出错情况,并返回Read timed out executing异常
     * @return
     */
    @GetMapping(value = "/payment/paymentFeignTimeout")
    public String paymentFeignTimeout() {
        //openfeign-ribbon客户端一般默认等待一分钟，但是服务端处理需要超过一分钟，超时后报错
        return paymentFeignService.paymentFeignTimeout();
        //为了避免出现这样的情况，有时候需要我们设置openFeign客户端的超时控制，只需要在YML文件中开启配置即可
    }

}
